using System;
using System.Configuration;
using System.Data;
using digit.Core;
using SMS.SmManager;

namespace SMS.ServiceManager
{
    public class ServiceDetailsManager
    {
        #region CONSTRUCTORS
        static ServiceDetailsManager()
        {
            _data = new ServiceDetailsData(Util.GetConnectionString("SMSSERVICE"));
            _error = "";
        }
        #endregion

        #region ATTRIBUTES
        private static ServiceDetailsData _data;
        private static string _error;
        #endregion

        #region PROPERTIES
        public static string ErrorMessage
        {
            get
            {
                return _error;
            }
        }

        #endregion

        #region METHODS
        public static bool Insert(string cmd1, string cmd2, string code1, string code2, string param1, string param2, string param3, string param4, string param5, string param6, string content1, string content2, string content3, string content4, string content5, string content6, string timer1, string timer2, string timer3, byte msgType, byte contentType, byte numOfMsg, byte processType, string serviceId, int groupCd, string createdBy, DateTime createdDate, byte status)
        {
            _error = "";
            try
            {
                object[] values = new object[28];
                values[0] = Util.ReplaceNullTo(cmd1, DBNull.Value);
                values[1] = Util.ReplaceNullTo(cmd2, DBNull.Value);
                values[2] = Util.ReplaceNullTo(code1, DBNull.Value);
                values[3] = Util.ReplaceNullTo(code2, DBNull.Value);
                values[4] = Util.ReplaceNullTo(param1, DBNull.Value);
                values[5] = Util.ReplaceNullTo(param2, DBNull.Value);
                values[6] = Util.ReplaceNullTo(param3, DBNull.Value);
                values[7] = Util.ReplaceNullTo(param4, DBNull.Value);
                values[8] = Util.ReplaceNullTo(param5, DBNull.Value);
                values[9] = Util.ReplaceNullTo(param6, DBNull.Value);
                values[10] = Util.ReplaceNullTo(content1, DBNull.Value);
                values[11] = Util.ReplaceNullTo(content2, DBNull.Value);
                values[12] = Util.ReplaceNullTo(content3, DBNull.Value);
                values[13] = Util.ReplaceNullTo(content4, DBNull.Value);
                values[14] = Util.ReplaceNullTo(content5, DBNull.Value);
                values[15] = Util.ReplaceNullTo(content6, DBNull.Value);
                values[16] = Util.ReplaceNullTo(timer1, DBNull.Value);
                values[17] = Util.ReplaceNullTo(timer2, DBNull.Value);
                values[18] = Util.ReplaceNullTo(timer3, DBNull.Value);
                values[19] = Util.ReplaceNullTo(msgType, DBNull.Value);
                values[20] = Util.ReplaceNullTo(contentType, DBNull.Value);
                values[21] = Util.ReplaceNullTo(numOfMsg, DBNull.Value);
                values[22] = Util.ReplaceNullTo(processType, DBNull.Value);
                values[23] = Util.ReplaceNullTo(serviceId, DBNull.Value);
                values[24] = Util.ReplaceNullTo(groupCd, DBNull.Value);
                values[25] = createdBy;
                values[26] = Util.ReplaceNullTo(createdDate, DBNull.Value);
                values[27] = status;

                return _data.Insert(values);
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return false;
            }
        }

        public static bool Insert(ServiceDetailsInfo info)
        {
            _error = "";
            try
            {
                object[] values = new object[28];
                values[0] = Util.ReplaceNullTo(info.Cmd1, DBNull.Value);
                values[1] = Util.ReplaceNullTo(info.Cmd2, DBNull.Value);
                values[2] = Util.ReplaceNullTo(info.Code1, DBNull.Value);
                values[3] = Util.ReplaceNullTo(info.Code2, DBNull.Value);
                values[4] = Util.ReplaceNullTo(info.Param1, DBNull.Value);
                values[5] = Util.ReplaceNullTo(info.Param2, DBNull.Value);
                values[6] = Util.ReplaceNullTo(info.Param3, DBNull.Value);
                values[7] = Util.ReplaceNullTo(info.Param4, DBNull.Value);
                values[8] = Util.ReplaceNullTo(info.Param5, DBNull.Value);
                values[9] = Util.ReplaceNullTo(info.Param6, DBNull.Value);
                values[10] = Util.ReplaceNullTo(info.Content1, DBNull.Value);
                values[11] = Util.ReplaceNullTo(info.Content2, DBNull.Value);
                values[12] = Util.ReplaceNullTo(info.Content3, DBNull.Value);
                values[13] = Util.ReplaceNullTo(info.Content4, DBNull.Value);
                values[14] = Util.ReplaceNullTo(info.Content5, DBNull.Value);
                values[15] = Util.ReplaceNullTo(info.Content6, DBNull.Value);
                values[16] = Util.ReplaceNullTo(info.Timer1, DBNull.Value);
                values[17] = Util.ReplaceNullTo(info.Timer2, DBNull.Value);
                values[18] = Util.ReplaceNullTo(info.Timer3, DBNull.Value);
                values[19] = Util.ReplaceNullTo(info.MsgType, DBNull.Value);
                values[20] = Util.ReplaceNullTo(info.ContentType, DBNull.Value);
                values[21] = Util.ReplaceNullTo(info.NumOfMsg, DBNull.Value);
                values[22] = Util.ReplaceNullTo(info.ProcessType, DBNull.Value);
                values[23] = Util.ReplaceNullTo(info.ServiceID, DBNull.Value);
                values[24] = Util.ReplaceNullTo(info.GroupCD, DBNull.Value);
                values[25] = info.CreatedBy;
                values[26] = Util.ReplaceNullTo(info.CreatedDate, DBNull.Value);
                values[27] = info.Status;

                return _data.Insert(values);
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return false;
            }
        }

        public static bool Update(long serviceDetailID, string cmd1, string cmd2, string code1, string code2, string param1, string param2, string param3, string param4, string param5, string param6, string param7, string content1, string content2, string content3, string content4, string content5, string content6, string timer1, string timer2, string timer3, byte msgType, byte contentType, byte numOfMsg, byte processType, string createdBy, string serviceId, int groupCd, DateTime createdDate, byte status)
        {
            _error = "";
            try
            {
                object[] values = new object[29];
                values[0] = serviceDetailID;
                values[1] = Util.ReplaceNullTo(cmd1, DBNull.Value);
                values[2] = Util.ReplaceNullTo(cmd2, DBNull.Value);
                values[3] = Util.ReplaceNullTo(code1, DBNull.Value);
                values[4] = Util.ReplaceNullTo(code2, DBNull.Value);
                values[5] = Util.ReplaceNullTo(param1, DBNull.Value);
                values[6] = Util.ReplaceNullTo(param2, DBNull.Value);
                values[7] = Util.ReplaceNullTo(param3, DBNull.Value);
                values[8] = Util.ReplaceNullTo(param4, DBNull.Value);
                values[9] = Util.ReplaceNullTo(param5, DBNull.Value);
                values[10] = Util.ReplaceNullTo(param6, DBNull.Value);
                values[11] = Util.ReplaceNullTo(content1, DBNull.Value);
                values[12] = Util.ReplaceNullTo(content2, DBNull.Value);
                values[13] = Util.ReplaceNullTo(content3, DBNull.Value);
                values[14] = Util.ReplaceNullTo(content4, DBNull.Value);
                values[15] = Util.ReplaceNullTo(content5, DBNull.Value);
                values[16] = Util.ReplaceNullTo(content6, DBNull.Value);
                values[17] = Util.ReplaceNullTo(timer1, DBNull.Value);
                values[18] = Util.ReplaceNullTo(timer2, DBNull.Value);
                values[19] = Util.ReplaceNullTo(timer3, DBNull.Value);
                values[20] = Util.ReplaceNullTo(msgType, DBNull.Value);
                values[21] = Util.ReplaceNullTo(contentType, DBNull.Value);
                values[22] = Util.ReplaceNullTo(numOfMsg, DBNull.Value);
                values[23] = Util.ReplaceNullTo(processType, DBNull.Value);
                values[24] = Util.ReplaceNullTo(serviceId, DBNull.Value);
                values[25] = Util.ReplaceNullTo(groupCd, DBNull.Value);
                values[26] = createdBy;
                values[27] = Util.ReplaceNullTo(createdDate, DBNull.Value);
                values[28] = status;

                return _data.Update(values);
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return false;
            }
        }

        public static bool Update(ServiceDetailsInfo info)
        {
            _error = "";
            try
            {
                object[] values = new object[29];
                values[0] = info.ServiceDetailID;
                values[1] = Util.ReplaceNullTo(info.Cmd1, DBNull.Value);
                values[2] = Util.ReplaceNullTo(info.Cmd2, DBNull.Value);
                values[3] = Util.ReplaceNullTo(info.Code1, DBNull.Value);
                values[4] = Util.ReplaceNullTo(info.Code2, DBNull.Value);
                values[5] = Util.ReplaceNullTo(info.Param1, DBNull.Value);
                values[6] = Util.ReplaceNullTo(info.Param2, DBNull.Value);
                values[7] = Util.ReplaceNullTo(info.Param3, DBNull.Value);
                values[8] = Util.ReplaceNullTo(info.Param4, DBNull.Value);
                values[9] = Util.ReplaceNullTo(info.Param5, DBNull.Value);
                values[10] = Util.ReplaceNullTo(info.Param6, DBNull.Value);
                values[11] = Util.ReplaceNullTo(info.Content1, DBNull.Value);
                values[12] = Util.ReplaceNullTo(info.Content2, DBNull.Value);
                values[13] = Util.ReplaceNullTo(info.Content3, DBNull.Value);
                values[14] = Util.ReplaceNullTo(info.Content4, DBNull.Value);
                values[15] = Util.ReplaceNullTo(info.Content5, DBNull.Value);
                values[16] = Util.ReplaceNullTo(info.Content6, DBNull.Value);
                values[17] = Util.ReplaceNullTo(info.Timer1, DBNull.Value);
                values[18] = Util.ReplaceNullTo(info.Timer2, DBNull.Value);
                values[19] = Util.ReplaceNullTo(info.Timer3, DBNull.Value);
                values[20] = Util.ReplaceNullTo(info.MsgType, DBNull.Value);
                values[21] = Util.ReplaceNullTo(info.ContentType, DBNull.Value);
                values[22] = Util.ReplaceNullTo(info.NumOfMsg, DBNull.Value);
                values[23] = Util.ReplaceNullTo(info.ProcessType, DBNull.Value);
                values[24] = Util.ReplaceNullTo(info.ServiceID, DBNull.Value);
                values[25] = Util.ReplaceNullTo(info.GroupCD, DBNull.Value);
                values[26] = Util.ReplaceNullTo(info.CreatedBy, DBNull.Value);
                values[27] = Util.ReplaceNullTo(info.CreatedDate, DBNull.Value);
                values[28] = info.Status;

                return _data.Update(values);
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return false;
            }
        }

        public static bool Delete(long serviceDetailID)
        {
            _error = "";
            try
            {
                object[] values = { serviceDetailID };
                return _data.Delete(values);
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return false;
            }
        }

        public static bool Delete(ServiceDetailsInfo info)
        {
            _error = "";
            try
            {
                object[] values = { info.ServiceDetailID };
                return _data.Delete(values);
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return false;
            }
        }

        public static ServiceDetailsInfo Select(long serviceDetailID)
        {
            _error = "";
            try
            {
                object[] values = { serviceDetailID };
                DataTable dTable = _data.Select(values);
                if (dTable.Rows.Count < 1) return null;

                ServiceDetailsInfo info = new ServiceDetailsInfo(dTable.Rows[0]);
                return info;
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return null;
            }
        }

        public static DataTable SelectAll()
        {
            _error = "";
            try
            {
                return _data.SelectAll();
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return null;
            }
        }

        public static DataTable SelectAllLottery()
        {
            _error = "";
            try
            {
                return _data.SelectAllLottery();
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return null;
            }
        }

        public static DataTable SearchInfo(string Key)
        {
            _error = "";
            try
            {
                return _data.SearchInfo(Key);
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return null;
            }
        }

        public static DataTable SelectByCode(string Code)
        {
            _error = "";
            try
            {
                return _data.SelectByCode(Code);
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return null;
            }
        }

        public static ServiceDetailsInfo VerifyForMsgOut_80(string strMessage, MsgIn_80Info objMsgIn)
        {
            object[] values = { strMessage, objMsgIn.MobileNo, objMsgIn.ServiceID };
            DataTable dTable = _data.VerifyForMsgOut(values);
            if (dTable.Rows.Count < 1) return null;

            ServiceDetailsInfo info = new ServiceDetailsInfo(dTable.Rows[0]);

            return info;
        }

        public static ServiceDetailsInfo VerifyForMsgOut_81(string strMessage, MsgIn_81Info objMsgIn)
        {
            object[] values = { strMessage, objMsgIn.MobileNo, objMsgIn.ServiceID };
            DataTable dTable = _data.VerifyForMsgOut(values);
            if (dTable.Rows.Count < 1) return null;

            ServiceDetailsInfo info = new ServiceDetailsInfo(dTable.Rows[0]);

            return info;
        }

        public static ServiceDetailsInfo VerifyForMsgOut_82(string strMessage, MsgIn_82Info objMsgIn)
        {
            object[] values = { strMessage, objMsgIn.MobileNo, objMsgIn.ServiceID };
            DataTable dTable = _data.VerifyForMsgOut(values);
            if (dTable.Rows.Count < 1) return null;

            ServiceDetailsInfo info = new ServiceDetailsInfo(dTable.Rows[0]);

            return info;
        }

        public static ServiceDetailsInfo VerifyForMsgOut_83(string strMessage, MsgIn_83Info objMsgIn)
        {
            object[] values = { strMessage, objMsgIn.MobileNo, objMsgIn.ServiceID };
            DataTable dTable = _data.VerifyForMsgOut(values);
            if (dTable.Rows.Count < 1) return null;

            ServiceDetailsInfo info = new ServiceDetailsInfo(dTable.Rows[0]);

            return info;
        }

        public static ServiceDetailsInfo VerifyForMsgOut_84(string strMessage, MsgIn_84Info objMsgIn)
        {
            object[] values = { strMessage, objMsgIn.MobileNo, objMsgIn.ServiceID };
            DataTable dTable = _data.VerifyForMsgOut(values);
            if (dTable.Rows.Count < 1) return null;

            ServiceDetailsInfo info = new ServiceDetailsInfo(dTable.Rows[0]);

            return info;
        }

        public static ServiceDetailsInfo VerifyForMsgOut_85(string strMessage, MsgIn_85Info objMsgIn)
        {
            object[] values = { strMessage, objMsgIn.MobileNo, objMsgIn.ServiceID };
            DataTable dTable = _data.VerifyForMsgOut(values);
            if (dTable.Rows.Count < 1) return null;

            ServiceDetailsInfo info = new ServiceDetailsInfo(dTable.Rows[0]);

            return info;
        }

        public static ServiceDetailsInfo VerifyForMsgOut_86(string strMessage, MsgIn_86Info objMsgIn)
        {
            object[] values = { strMessage, objMsgIn.MobileNo, objMsgIn.ServiceID };
            DataTable dTable = _data.VerifyForMsgOut(values);
            if (dTable.Rows.Count < 1) return null;

            ServiceDetailsInfo info = new ServiceDetailsInfo(dTable.Rows[0]);

            return info;
        }

        public static ServiceDetailsInfo VerifyForMsgOut_87(string strMessage, MsgIn_87Info objMsgIn)
        {
            object[] values = { strMessage, objMsgIn.MobileNo, objMsgIn.ServiceID };
            DataTable dTable = _data.VerifyForMsgOut(values);
            if (dTable.Rows.Count < 1) return null;

            ServiceDetailsInfo info = new ServiceDetailsInfo(dTable.Rows[0]);

            return info;
        }

        public static ServiceDetailsInfo VerifyForMsgOut_Partner(string strMessage, MsgIn_PartnerInfo objMsgIn)
        {
            object[] values = { strMessage, objMsgIn.MobileNo, objMsgIn.ServiceID };
            DataTable dTable = _data.VerifyForMsgOut(values);
            if (dTable.Rows.Count < 1) return null;

            ServiceDetailsInfo info = new ServiceDetailsInfo(dTable.Rows[0]);

            return info;
        }

        #endregion

    }
}